-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix particle system with unlit mesh emitter #7795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR restores rendering of unlit mesh particle emitters by decoupling the normal‐mapping flag from lighting and introducing a separate LIGHTING define.
- Add a
LIGHTINGdefine in shader generation when lighting is enabled - Guard shading blocks in both WGSL and GLSL shaders with
LIGHTING && NORMAL != NONE - Update
ParticleMaterialto supplylightingand to use vertex normals for unlit mesh emitters
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/scene/shader-lib/wgsl/chunks/particle/frag/particle-shader.js | Only run lighting shading when LIGHTING is defined |
| src/scene/shader-lib/glsl/chunks/particle/frag/particle-shader.js | Mirror WGSL change in GLSL |
| src/scene/shader-lib/programs/particle.js | Set LIGHTING define based on emitter option |
| src/scene/particle-system/particle-material.js | Pass new lighting flag and adjust normal for unlit meshes |
Comments suppressed due to low confidence (2)
src/scene/particle-system/particle-material.js:48
- This new branch (
lighting === false && useMesh === true) handles unlit mesh normals. Consider adding a dedicated test case to verify that unlit mesh particles render correctly with vertex normals when lighting is off.
normal: emitter.lighting ? ((emitter.normalMap !== null) ? 2 : 1) : (this.emitter.useMesh ? 1 : 0),
src/scene/shader-lib/wgsl/chunks/particle/frag/particle-shader.js:45
- Using
#if LIGHTINGwith a define that has no explicit numeric value can lead to preprocessor ambiguity. Consider using#ifdef LIGHTINGor definingLIGHTINGas1to ensure the condition is evaluated as intended.
#if LIGHTING && NORMAL != NONE
I have not checked in detail, but is particle shader using normals for any other reason? |
|
Anything left preventing this from being merged? |
Currently, mesh particle emitters with
lighting: falsewill not render in either WebGL2 or WebGPU. For a repro, look at https://playcanvas.vercel.app/#/graphics/particles-mesh and toggle thelightingoption.I think the main issue is that we are using the
NORMALdefine as a proxy for whether to use lighting, but in the case of an unlit mesh we do want mesh normals, we just don't want that mesh to be shaded.This PR restores rendering for unlit mesh emitters by:
Try the latest preview deployment on this PR and you will see that now, on the particles-mesh example, particles are still rendered when
lightingis off. We can also see that the shading on those particles is flat. If you reduce the directional light intensity to 0.01 in this scene, you will see that the particles are not affected by the light whenlightingis off.I confirm I have read the contributing guidelines and signed the Contributor License Agreement.